package com.yuecai.modules.activity_coupon;


import com.yuecai.modules.activity_coupon.domain.dto.YcActivityGiveCouponDto;
import com.yuecai.modules.activity_coupon.service.impl.YcActivityGiveCouponService;
import com.yuecai.utils.SecurityUtils;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dm
 * @since 2021-01-28
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/activity-coupon")
public class YcActivityCouponController {

    private final YcActivityGiveCouponService ycActivityGiveCouponService;

    @GetMapping
    @ApiOperation("查询优惠券包")
    public ResponseEntity<Object> query(YcActivityGiveCouponDto dto){
        String currentUsername = SecurityUtils.getCurrentUsername();
        Long aLong = Long.valueOf(currentUsername);
        return ResponseEntity.ok(ycActivityGiveCouponService.queryActivityGiveCouponUser(dto,aLong));
    }



    @GetMapping("/get")
    @ApiOperation("领取")
    public ResponseEntity<Object> getCouponActivity(YcActivityGiveCouponDto dto) throws Exception {
        if (dto.getId()==null){
            throw new Exception("请选择优惠券包！");
        }
        String currentUsername = SecurityUtils.getCurrentUsername();
        Long aLong = Long.valueOf(currentUsername);
        return ResponseEntity.ok(ycActivityGiveCouponService.getCouponActivity(dto,aLong));
    }

}